<template>
  <V-CommonHeaderLeft>
    <div class="stockDetails">
      <Navigation :msg="navMsg"></Navigation>
      <div class="stocktable">
        <el-table ref="multipleTable"
                  :data="stock"
                  style="width: 100%;"
                  :height="tableHeight"
                  class="table-class">
          <el-table-column type="index"
                           min-width="5%"
                           label="序号"></el-table-column>
          <el-table-column prop="id"
                           min-width="7.92%"
                           label="单号">
            <template slot-scope="scope">
              <span :title="scope.row.id">{{ scope.row.id }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="name"
                           label="商品名称"
                           min-width="7.92%"
                           sortable>
            <template slot-scope="scope">
              <span :title="scope.row.name">{{ scope.row.name }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="orderId"
                           label="商品编号"
                           min-width="7.92%"
                           sortable>
            <template slot-scope="scope">
              <span :title="scope.row.orderId">{{ scope.row.orderId }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="size"
                           min-width="7.92%"
                           label="规格">
            <template slot-scope="scope">
              <span :title="scope.row.size">{{ scope.row.size }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="sizeId"
                           min-width="7.92%"
                           label="规格编号">
            <template slot-scope="scope">
              <span :title="scope.row.sizeId">{{ scope.row.sizeId }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="belongStock"
                           min-width="7.92%"
                           label="所属仓库">
            <template slot-scope="scope">
              <span :title="scope.row.belongStock">{{ scope.row.belongStock }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="work"
                           min-width="7.92%"
                           label="业务"
                           sortable>
            <template slot-scope="scope">
              <span :title="scope.row.work">{{ scope.row.work }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="time"
                           min-width="7.92%"
                           label="出入库日期">
            <template slot-scope="scope">
              <span :title="scope.row.time">{{ scope.row.time }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="num"
                           min-width="7.92%"
                           label="数量"
                           sortable>
            <template slot-scope="scope">
              <span v-if="scope.row.num >= 0"
                    class="text-green">+{{ scope.row.num }}</span>
              <span v-else
                    class="text-red">{{ scope.row.num }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="unit"
                           min-width="7.92%"
                           label="单位">
            <template slot-scope="scope">
              <span :title="scope.row.unit">{{ scope.row.unit }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="systemStock"
                           label="系统库存"
                           min-width="7.92%"
                           sortable>
            <template slot-scope="scope">
              <span :title="scope.row.systemStock">{{ scope.row.systemStock }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="remarks"
                           min-width="7.88%"
                           label="备注">
            <template slot-scope="scope">
              <span :title="scope.row.remarks">{{ scope.row.remarks }}</span>
            </template>
          </el-table-column>
        </el-table>
        <Paging :msg="pageMsg.length"
                ref="fn"
                @pageNum="getPageNum"
                @pageId="getPageId"></Paging>
      </div>
    </div>
  </V-CommonHeaderLeft>
</template>
<script>
import VCommonHeaderLeft from '@/components/common/vCommonHeaderLeft/VCommonHeaderLeft'
import Navigation from '@/components/common/navigation/Navigation'
import Paging from '@/components/common/paging/Paging'
export default {
  data () {
    return {
      tableHeight: '',
      pageNum: 15, // 每页默认显示15条,
      pageId: 1, // 页面id
      navMsg: [
        {
          name: '仓库',
          path: '/outStock'
        },
        {
          name: '出入库明细',
          path: ''
        }
      ],
      stock: [],
      pageMsg: [
        {
          id: '1',
          outStock: '深圳仓',
          inStock: '广州仓',
          orderStatus: '已完成',
          outTime: '2018-08-24 11:29:36',
          inTime: '2018-08-24 11:29:44',
          orderPerson: '陈素然',
          remarks: '啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦',
          num: -1
        },
        {
          id: '2',
          outStock: '深圳仓',
          inStock: '广州仓',
          orderStatus: '已完成',
          outTime: '2018-08-24 11:29:46',
          inTime: '2018-08-24 11:29:54',
          orderPerson: '陈素然',
          remarks: '',
          num: 1
        }
      ]
    }
  },
  components: {
    Navigation,
    Paging,
    VCommonHeaderLeft
  },
  methods: {
    getHight () {
      this.tableHeight = window.innerHeight - 162 + 'px'
    },
    getPageId (id = 1) {
      this.pageId = id
      this.stock = this.$refs.fn.sliceArray(this.pageMsg, this.pageNum, id - 1)
    },
    getPageNum (num) {
      this.pageNum = num
      this.getPageId()
    }
  },
  created () {
    this.stock = this.pageMsg
    this.getHight()
    window.addEventListener('resize', this.getHight)
  },
  destroyed () {
    window.removeEventListener('resize', this.getHight)
  }
}
</script>
<style lang="scss" scoped>
.stockDetails {
  width: 100%;
  margin-right: 10px;
  overflow: hidden;
  .stocktable {
    @mixin el-common($el-color, $el-height, $el-class) {
      padding: 0;
      color: $el-color;
      height: $el-height;
      line-height: $el-height;
      &:first-child {
        text-align: center;
      }
      &:not(:first-child) {
        #{$el-class} {
          width: 100%;
          line-height: 20px;
          display: -webkit-box;
          overflow: hidden;
          white-space: normal !important;
          text-overflow: ellipsis;
          word-wrap: break-word;
          word-break: break-all;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }
    }
    /deep/ .el-table__body-wrapper {
      overflow-y: hidden;
      &:hover {
        overflow-y: overlay;
      }
      &::-webkit-scrollbar {
        width: 8px;
        height: 50%;
      }
      &::-webkit-scrollbar-thumb {
        border-radius: 10px;
        background-color: rgba(0, 0, 0, 0.2);
      }
      &::-webkit-scrollbar-track {
        border-radius: 0;
        background-color: rgba(0, 0, 0, 0.1);
      }
    }
    /deep/ .table-class {
      font-size: 12px;
      padding: 0;
      tr {
        td {
          @include el-common(
            $el-color: #333,
            $el-height: 40px,
            $el-class: "span"
          );
          &:nth-child(2) {
            &:hover {
              cursor: pointer;
              color: #20bdeb;
            }
          }
        }
        th {
          @include el-common(
            $el-color: #666,
            $el-height: 50px,
            $el-class: ".cell"
          );
          font-weight: normal;
          background-color: #fcfcfc;
        }
        .text-red {
          color: #ff3838;
        }
        .text-green {
          color: #20ade5;
        }
      }
    }
  }
}
</style>
